package me.miencraft.plugin.worldinfo;

import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author langle__
 * @version 1.0
 */
public class Placeholder extends PlaceholderExpansion {

    @Override
    public @NotNull String getIdentifier() {
        return "worldinfo";
    }

    @Override
    public @NotNull String getAuthor() {
        return "langle__";
    }

    @Override
    public @NotNull String getVersion() {
        return "1.0.0";
    }

    @Override
    public boolean persist() {
        return true;
    }

    @Override
    public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) {
        World world = player.getWorld();
        Location location = player.getLocation();

        switch (params) {
            case "time":
                return String.valueOf(world.getTime());
            case "time_form":
                return WorldInfoUtil.timeFormat(world.getTime());
            case "moon_phase":
                return String.valueOf(MoonPhase.fromWorldTime(world).getIndex());
            case "weather_duration":
                return String.valueOf(WorldInfoUtil.getCurrentWeatherDuration(world));
            case "weather_duration_seconds":
                return String.valueOf(WorldInfoUtil.getSecondsFromTick(WorldInfoUtil.getCurrentWeatherDuration(world)));
            case "weather_duration_minutes":
                return String.valueOf(WorldInfoUtil.getMinutesFromTick(WorldInfoUtil.getCurrentWeatherDuration(world)));
            case "weather_duration_hours":
                return String.valueOf(WorldInfoUtil.getHoursFromTick(WorldInfoUtil.getCurrentWeatherDuration(world)));
            case "weather_duration_form":
                return WorldInfoUtil.formatTickToCustomString(WorldInfoUtil.getCurrentWeatherDuration(world), false);
            case "weather_name":
                return WorldInfoUtil.formatFrom(WeatherType.fromWorldWeather(world));
            case "time_name":
                return WorldInfoUtil.formatFrom(TimeType.fromGameTick((int) world.getTime()));
            case "biome_name":
                return WorldInfoUtil.formatFrom(location.getBlock().getBiome());
            case "moon_phase_name":
                return WorldInfoUtil.formatFrom(MoonPhase.fromWorldTime(world));
        }

        return null;
    }

}
